<?php

$query = implode("", file("/home/umkus/Desktop/products_some_title.sql"));

$max = 1000000;

$q = '';

$pos = 0;

$result = array();

while (strlen($query) > $max)
{
	$q = substr($query, $pos);
	$q = substr($q, 0, $max);
	$q = preg_replace("~;[^;]*$~s", ";", $q);

	$pos += strlen($q);

	$query = substr($query, $pos);

	$result[] = $q;
	//	$result .= $q;
}
//leftovers
$result[] = $query;


foreach ($result as $key=>$item)
{
	$fp = fopen('/home/umkus/Desktop/test_'.$key.'.sql', 'w');
	fwrite($fp, $item);
	fclose($fp);
}



//$result .= $q;

?>